import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersistence from 'vuex-persist'

// 更新state时，帮你自动完成本存储的添加、更新；F5刷新页面时，自动获取本地存储的数据给state
const vuexLocal = new VuexPersistence({
  storage: window.localStorage
})

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    userInfo: {}
  },
  getters: {},
  mutations: {
    tokenMt(state, payload) {
      state.token = payload
    },
    userInfoMt(state, payload) {
      state.userInfo = payload
    }
  },
  actions: {},
  modules: {},
  plugins: [vuexLocal.plugin]
})
